package com.qcby.front.controller;


import com.qcby.framwork.utils.AppHttpCodeEnum;
import com.qcby.framwork.utils.ResponseResult;
import com.qcby.framwork.utils.SystemException;
import com.qcby.front.model.SysUser;
import com.qcby.front.service.BlogLoginService;
import org.apache.catalina.User;
import org.apache.poi.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BlogLoginController {

    @Autowired
    private BlogLoginService blogLoginService;
    @PostMapping("/login")
    public ResponseResult login(@RequestBody SysUser user){
        //提示必须填写用户名
        if(!StringUtils.hasText(user.getUserName())){
            throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);
        }

        return blogLoginService.login(user);
    }
    @PostMapping("/logout")
    public ResponseResult logout(){
        return blogLoginService.logout();
    }
}
